//
//  CZBaseTableViewController.swift
//  项目框架
//
//  Created by yang on 16/2/25.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZBaseTableViewController: UITableViewController,CZVisitorDelegate {

    
    //父类定义一个属性，子类可以继承
    var visitor:CZVisitor?
    
    //定义一个属性来判断是否登录
    var isLogin:Bool = CZUserViewModel.shareInstance.isLogin!
    
    override func loadView() {
        
        if CZUserViewModel.shareInstance.isLogin!{
        
            super.loadView()
        }else{
        
            showVisitorView()
        }
    }
    
    private func showVisitorView(){
    
        visitor = CZVisitor()
        
        visitor?.delegate = self
        
        view = visitor
        
        setupNav()
    
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
     
        
    }
    
    private func setupNav(){
    
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didRegister")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "didLogin")
    
    }
    func didLogin(){
        print("登录")
    
    }
    func didRegister(){
    
        let login = CZLoginViewController()
        
        let nav = UINavigationController(rootViewController: login)
        
        presentViewController(nav, animated: true) { () -> Void in
            
        }
    }
}
